package routes

import (
	"soma-server/controller/system"
	"soma-server/middleware"

	"github.com/gin-gonic/gin"
)

func InitApiRoutes(r *gin.RouterGroup, authMiddleware *middleware.JWTMiddleware) gin.IRoutes {
	apiController := controller.NewApiController()
	router := r.Group("/api")
	// 开启jwt认证中间件
	router.Use(authMiddleware.JWTAuthMiddleware())
	// 开启casbin鉴权中间件
	router.Use(middleware.CasbinMiddleware())
	{
		// 获取接口管理列表
		router.POST("/list", apiController.GetApis)
		// 获取接口树结构
		router.GET("/tree", apiController.GetApiTree)
		// 创建接口
		router.POST("/create", apiController.CreateApi)
		// 更新接口
		router.PUT("/update/:apiId", apiController.UpdateApiById)
		// 删除接口
		router.DELETE("/delete/batch", apiController.BatchDeleteApiByIds)
	}

	return r
}
